import fetch from 'common/src/utils/fetch';

function assertNotNull(...args){
  for (let i = 0; i < args.length; i++) {
    if  (args[i] == null || args[i] === "") //0是可以的
      throw "参数不能为空"
  }
  return true;
}
/**
 * 教师课表
 * @param {Number} calendarId  学期id
 * @param {String} teacherCode 教师code
 * @param {boolean} showTeacher 是否全量老师信息
 */
export function getTeacherTimetable(calendarId, teacherCode, showTeacher) {
  return fetch({
    url: `/api/arrangementservice/timetable/teacher`,
    method: 'get',
    params: {"code":teacherCode,calendarId,showTeacher},
  })
}

/**
 * 教师课表中教师排课列表数据
 * @param {Number} calendarId  学期id
 * @param {String} teacherCode 教师code
 */
export function teacherTimeTableList(calendarId, teacherCode) {
  assertNotNull(calendarId, teacherCode);
  return fetch({
    url: `/api/arrangementservice/timetable/teacherTimeTableList`,
    method: 'get',
    params: {"code":teacherCode,calendarId},
  })
}

/**
 * 教师课表(集合)
 * @param {Number} calendarId  学期id
 * @param {Array<String>} teacherCodes 教师code
 */
export function getTeachersTimetable(calendarId, teacherCodes) {
  return fetch({
    // url: `/api/arrangementservice/timetable/teachers?calendarId=${calendarId}&teacherCodes=${teacherCodes.join(',')}`,
    url: `/api/arrangementservice/timetable/teachers`,
    method: 'get',
    params:{calendarId,teacherCodes}
  })
}

/**
 * 建议专业课表
 * @param {Number} calendarId  学期id
 * @param {String} majorCode 专业code
 * @param {number} grade 专业年级，不填或者0为研究生
 * @param {String} directions 方向
 */
export function getMajorTimetable(calendarId,majorCode,grade,directions,isMajor) {
  if(null ==isMajor){
    isMajor =false;
  }
  assertNotNull(calendarId,majorCode);
  if(!grade){
    grade = 0;
  }
  return fetch({
    url: `/api/arrangementservice/timetable/major?code=${majorCode}&grade=${grade}&calendarId=${calendarId}&dirCode=${directions}&isMajor=${isMajor}`,
    method: 'get'
  })
}

/**
 * 建议专业课表
 * @param {Number} calendarId  学期id
 * @param {String} majorCode 专业code
 * @param {number} grade 专业年级，不填或者0为研究生
 * @param {String} directions 方向
 * @param {number} isPro 排课类型
 */
export function getMajorTimetableForPro(calendarId,majorCode,grade,directions,isMajor,isPro) {
    if(null ==isMajor){
      isMajor =false;
    }
    assertNotNull(calendarId,majorCode);
    if(!grade){
      grade = 0;
    }
    return fetch({
      url: `/api/arrangementservice/timetable/majorForProTable?code=${majorCode}&grade=${grade}&calendarId=${calendarId}&dirCode=${directions}&isMajor=${isMajor}&isPro=${isPro}`,
      method: 'get'
    })
  }

/**
 * 教学班相关（教师、建议专业）课程所占时间
 * @param {Number} teachingClassId  教学班id
 * @param {Number} type 排课结果类型 1:预排课 2:正式排课
 */
export function getLessonRelationTimetable(teachingClassId, type) {
  assertNotNull(teachingClassId);
  if (!type) {
    type = 2;
  }
  return fetch({
    url: `/api/arrangementservice/timetable/lessonRelation/${teachingClassId}?type=${type}`,
    method: 'get'
  })
}

/**
 * 教学班所占时间
 * @param {Number} teachingClassId  学期id
 * @param {Number} type 0:全部 1:预排课 2:排课
 */
export function getLessonTimetable(teachingClassId,type) {
  assertNotNull(teachingClassId);
  if(!type){
    type = 0;
  }
  return fetch({
    url: `/api/arrangementservice/timetable/lesson/${teachingClassId}?type=${type}`,
    method: 'get'
  })
}

/**
 * 根据课号查询排课信息
 * @param {String} courseCode  课号
 * @param {Number} calendarId 学期Id
 */
export function getCourseTimetable(courseCode,calendarId,campus) {
  assertNotNull(courseCode,calendarId);
  return fetch({
    url: `/api/arrangementservice/timetable/course/${courseCode}?calendarId=${calendarId}&campus=${campus}`,
    method: 'get'
  })
}

export function getStudentList(data) {
  return fetch({
    url: '/api/electionservice/elcCourseTake/page',
    method: 'post',
    headers: { 'Content-Type': 'application/json' },
    data
  })
}
